#ifndef HIBERNATECOLLECTION_H
#define HIBERNATECOLLECTION_H

#ifndef FALLOC_H
# error must include falloc
#endif
#ifndef CORE_H
# include "..\..\..\Core\System\Core.h"
#endif
#include "Limits.h"
#include "Hibernate.hpp"

namespace System { namespace Scheduler {
	
	class SliceCollection;

	typedef struct
	{
	public:
		fallocContext* _fallocCtx;
		Hibernate _hibernates[EngineSettings__MaxHibernates];

        __device__ void xtor(fallocHeap* heap)
        {
			trace(HibernateCollection, "xtor");
			_fallocCtx = fallocCreateCtx(heap);
            for (int hibernateIndex = 0; hibernateIndex < EngineSettings__MaxHibernates; hibernateIndex++)
                _hibernates[hibernateIndex].xtor(_fallocCtx);
        }
		__device__ void Dispose()
		{
			trace(HibernateCollection, "Dispose");
			fallocDisposeCtx(_fallocCtx);
		}

        __device__ void Hibernate(Element* element, ulong time)
        {
			trace(HibernateCollection, "Hibernate %d", TimePrec__DecodeTime(time));
            Scheduler::Hibernate* hibernate = &_hibernates[0];
            hibernate->Elements.Add(element, time);
        }

		 __device__ void DeHibernate(SliceCollection* slices)
        {
			trace(HibernateCollection, "DeHibernate");
            Scheduler::Hibernate* hibernate = &_hibernates[0];
            hibernate->Elements.DeHibernate(slices);
        }

        __device__ void ReShuffle()
        {
			trace(HibernateCollection, "ReShuffle");
        }

	} HibernateCollection;

}}

#endif // HIBERNATECOLLECTION_H
